///////////////////////////////////////////////////////////////////////////////
// Project: Hoyo Client Game
//
// hy_server_monster_data.cpp
// Created: 2013-7-30
// Author: Like Cheng
///////////////////////////////////////////////////////////////////////////////

#include "hy_server_monster_data.h"
#include "hy_common_system/hy_common_func.h"

hy_server_monster_data::hy_server_monster_data()
{
	init();
}

hy_server_monster_data::~hy_server_monster_data()
{

}

bool hy_server_monster_data::init()
{
	m_monster_id = 0;
	m_value.clear();
	m_load_dirty = 0;
	return true;
}

void hy_server_monster_data::set_value( Json::Value& v )
{
	m_value = v;
	m_load_dirty = 1;
}
///////////////////////////////////////////////////////////////////////////////
hy_server_monster_mgr* hy_server_monster_mgr_instance = NULL;

hy_server_monster_mgr::hy_server_monster_mgr()
{

}

hy_server_monster_mgr::~hy_server_monster_mgr()
{

}

hy_server_monster_mgr* hy_server_monster_mgr::instance()
{
	if( hy_server_monster_mgr_instance == NULL )
		hy_server_monster_mgr_instance = new hy_server_monster_mgr;
	return hy_server_monster_mgr_instance;
}

void hy_server_monster_mgr::purge_instance()
{
	DEL_POINTER( hy_server_monster_mgr_instance );
}

bool hy_server_monster_mgr::add_server_monster_data( hy_server_monster_data* d , bool is_update )
{
	hy_server_monster_data_map::iterator it = m_server_monster_data_map.find( d->get_id() );
	if( it != m_server_monster_data_map.end() )
	{
		if( is_update )
		{
			delete it->second;
			it->second = d;
			return true;
		}
	}
	else
	{
		m_server_monster_data_map.insert( std::make_pair( d->get_id(), d ) );
	}
	return true;
}

hy_server_monster_data*	hy_server_monster_mgr::get_server_monster_data( int id )
{
	hy_server_monster_data_map::iterator it = m_server_monster_data_map.find( id );
	if( it != m_server_monster_data_map.end() )
	{
		return it->second;
	}
	return NULL;
}